/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VistaPrincipal.java
 *
 * Created on 14-ene-2011, 1:03:27
 */

package Vista;

import Vista.Anuncio.AnuncioView;
import Vista.Sesion.SesionView;
import Vista.Tarea.TareaView;
import Vista.TareaRealizada.TareaRealizadaView;
import Vista.Usuario.UsuarioView;
import javax.swing.JPanel;

/*
 *  Proyecto eJAM [G12]
 *  Miembros:
 *      - Javier Ruiz Hidalgo
 *      - Adrian Ramos Cápitas
 *      - Miguel Alejandro Esteban Ordóñez
 */

public class VistaPrincipal extends javax.swing.JFrame {

    private UsuarioView usuarioView;
    private TareaView tareaView;
    private TareaRealizadaView tareaRealizadaView;
    private SesionView sesionView;
    private AnuncioView anuncioView;
    private InicioSesionPanel inicioSesion;
    private FinSesionPanel finSesionPanel;

    /** Creates new form VistaPrincipal */
    public VistaPrincipal(UsuarioView usuarioView, TareaView tareaView, TareaRealizadaView tareaRealizadaView, SesionView sesionView, AnuncioView anuncioView) {
        initComponents();

        inicioSesion = new InicioSesionPanel(sesionView, usuarioView, this);
        this.jPanelIdentificacion.add(this.inicioSesion);

        this.usuarioView = usuarioView;
        this.tareaView = tareaView;
        this.tareaRealizadaView = tareaRealizadaView;
        this.sesionView = sesionView;
        this.anuncioView = anuncioView;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelPestañasPrincipal = new javax.swing.JTabbedPane();
        jCerrar = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jPanelIdentificacion = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Menú Principal");

        jCerrar.setText("Cerrar");
        jCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCerrarActionPerformed(evt);
            }
        });

        jPanelIdentificacion.setPreferredSize(new java.awt.Dimension(480, 50));
        jPanelIdentificacion.setLayout(new javax.swing.BoxLayout(jPanelIdentificacion, javax.swing.BoxLayout.LINE_AXIS));

        jLabel1.setFont(new java.awt.Font("Sakkal Majalla", 3, 48));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("eJAM v1.0");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanelIdentificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(8, 8, 8))
                    .addComponent(jPanelPestañasPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, 800, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 737, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jCerrar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, 0, 0, Short.MAX_VALUE)
                    .addComponent(jPanelIdentificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jPanelPestañasPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, 600, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCerrar)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCerrarActionPerformed
        System.exit(NORMAL);
    }//GEN-LAST:event_jCerrarActionPerformed

    /**
    * @param args the command line arguments
    */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jCerrar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanelIdentificacion;
    private javax.swing.JTabbedPane jPanelPestañasPrincipal;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables

    public void iniciaPestañasGlobales(String privilegio){
        if(privilegio.equals("class Modelo.Entidades.AlumnoImpl")){
            this.anuncioView.dataModelChanged();
            this.jPanelPestañasPrincipal.add("Gestión de Anuncios", (JPanel)anuncioView);
            this.tareaRealizadaView.iniciaPestañasParciales(SesionActual.instancia().obtieneSesion().getUsuario().getClass().toString());
            this.jPanelPestañasPrincipal.add("Realización de Evaluaciones", (JPanel)tareaRealizadaView);
        }
        else{
            if(privilegio.equals("class Modelo.Entidades.ProfesorImpl")){
                this.jPanelPestañasPrincipal.add("Gestión de Evaluaciones", (JPanel)tareaView);
                this.tareaRealizadaView.iniciaPestañasParciales(SesionActual.instancia().obtieneSesion().getUsuario().getClass().toString());
                this.jPanelPestañasPrincipal.add("Realización de Evaluaciones", (JPanel)tareaRealizadaView);
            }
            else{
                this.jPanelPestañasPrincipal.add("Gestión de Usuarios", (JPanel)usuarioView);
                this.jPanelPestañasPrincipal.add("Gestión de Evaluaciones", (JPanel)tareaView);
                this.tareaRealizadaView.iniciaPestañasParciales(SesionActual.instancia().obtieneSesion().getUsuario().getClass().toString());
                this.jPanelPestañasPrincipal.add("Realización de Evaluaciones", (JPanel)tareaRealizadaView);
                this.jPanelPestañasPrincipal.add("Gestión de Sesiones", (JPanel)sesionView);
            }
        }
    }

    public void refrescaVista(){
        iniciaPestañasGlobales(SesionActual.instancia().obtieneSesion().getUsuario().getClass().toString());
    }

    public void añadePanelDesconexion(){
        this.jPanelIdentificacion.remove(this.inicioSesion);
        this.finSesionPanel = new FinSesionPanel(this);
        this.jPanelIdentificacion.add(this.finSesionPanel);
    }

    public void desconectar(){
        this.jPanelPestañasPrincipal.removeAll();
        this.tareaRealizadaView.borraPestañas();
        this.jPanelIdentificacion.remove(this.finSesionPanel);
        this.inicioSesion = new InicioSesionPanel(sesionView, usuarioView, this);
        this.jPanelIdentificacion.add(this.inicioSesion);
    }
}
